//
//  Date.h
//  Calendar
//
//  Created by 曾玮 on 15/1/18.
//
//

#ifndef Calendar_Date_h
#define Calendar_Date_h

#include <time.h>

struct Date
{
    int year;
    int mon; // [0, 11]
    int day; // [1, 31]
    
    Date() : year(1900), mon(0), day(1) { }
    Date(int yy, int mm, int dd) : year(yy), mon(mm), day(dd) { }
    Date(const struct tm& t) : year(t.tm_year + 1900), mon(t.tm_mon), day(t.tm_mday) { }
    
    bool operator<(const Date& other) const
    {
        return year < other.year ||
        (year == other.year && mon < other.mon) ||
        (year == other.year && mon == other.mon && day < other.day);
    }
    
    bool operator==(const Date& other) const
    {
        return year == other.year && mon == other.mon && day == other.day;
    }
    
    bool operator!=(const Date& other) const
    {
        return year != other.year || mon != other.mon || day != other.day;
    }
};

struct LunarDate : public Date
{
    bool leapMonth;
    
    LunarDate() : leapMonth(false) { }
    LunarDate(int yy, int mm, int dd, bool leap) : Date(yy, mm, dd), leapMonth(leap) { }
};

struct DateTime : public Date
{
    int hour;
    int min;
    double sec;
    
    DateTime() : hour(0), min(0), sec(0) { }
    DateTime(const Date& date, int h = 0, int m = 0, double s = 0.0) : Date(date), hour(h), min(m), sec(s) { }
    
    void setDate(const Date& date)
    {
        year = date.year;
        mon = date.mon;
        day = date.day;
    }

    void setTime(int h, int m, double s = 0)
    {
        hour = h;
        min = m;
        sec = s;
    }
};

#endif
